package com.ruoyi.project.sales.orders.create.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.sales.orders.create.domain.CustomerOrder;
import com.ruoyi.project.sales.orders.create.domain.NewOrder;
import com.ruoyi.project.sales.orders.create.domain.ProductOrder;
import com.ruoyi.project.sales.orders.create.mapper.OrderCreateMapper;
import com.ruoyi.project.sales.orders.create.mapper.OrderCustomerMapper;
import com.ruoyi.project.sales.orders.create.mapper.OrderProductMapper;
import com.ruoyi.project.sales.orders.search.domain.OrderProduct;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.domain.UserPost;
import com.ruoyi.project.system.user.domain.UserRole;
import com.ruoyi.project.system.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderCreateServiceImpl implements IOrderCreateService{

    @Autowired
    private OrderCreateMapper orderCreateMapper;

    @Autowired
    private OrderCustomerMapper orderCustomerMapper;

    @Autowired
    private OrderProductMapper orderProductMapper;

    @Override
    public int insertOrder(NewOrder order) {
        // 新增订单表, 产品表, 客户表信息
        int rows = orderCreateMapper.insertOrder(order);
        int rows2 = orderCreateMapper.insertCustomer(order);
        int rows3 = orderCreateMapper.insertProduct(order);
        // 新增产品关联表信息
        orderProductMapper(order);
        // 新增客户关联表信息
        orderCustomerMapper(order);
        return rows;
    }
    /**
     * 新增客户信息
     *
     * @param order 用户对象
     */
    public void orderCustomerMapper(NewOrder order)
    {
        int customerId = order.getCustomerId();
        CustomerOrder co = new CustomerOrder();
        co.setCustomerId(customerId);
        co.setOrderId(order.getOrderId());
        orderCustomerMapper.batchOrderCustomer(co);
    }
    /**
     * 新增产品信息
     *
     * @param order 用户对象
     */
    public void orderProductMapper(NewOrder order)
    {
        int productId = order.getProductId();
        ProductOrder po = new ProductOrder();
        po.setProductId(productId);
        po.setOrderId(order.getOrderId());
        orderProductMapper.batchOrderProduct(po);
    }


}
